<template>
  <div class="healthInfo pd-20">
    <el-input v-model="param.searchCondition"
              placeholder="请输入医院名称"
              class="w-200"
              clearable
              @clear="handle(1,0)"></el-input>
    <el-select v-model="param.level"
               class="w-200"
               clearable
               placeholder="医院等级"
               @clear="handle(1,0)">
      <el-option v-for="item in typeItems"
                 :key="item.level"
                 :label="item.name"
                 :value="item.level">
      </el-option>
    </el-select>
    <el-button @click="handle(1,0)"
               type="primary">查 询
    </el-button>
    <el-button @click="handle(2,0)"
               type="primary">新 增
    </el-button>
    <el-button type="warning"
               @click="initCooperation">初始化活动网点
    </el-button>
    <el-table :data="tableData"
              style="width: 100%"
              border
              class="mt-20">
      <el-table-column align="center"
                       type="index"
                       min-width="20"></el-table-column>
      <el-table-column align="center"
                       label="医院logo"
                       width="100">
        <template slot-scope="scoped">
          <img :src="scoped.row.imageUrl"
               style="height:30px;width:30px"
               @click="seeImg(scoped.row.imageUrl)">
        </template>
      </el-table-column>
      <el-table-column align="center"
                       prop="name"
                       label="医院名称"></el-table-column>
      <el-table-column align="center"
                       label="医院等级"
                       :formatter="hospitallevel"></el-table-column>
      <el-table-column align="center"
                       prop="property"
                       label="医院性质">
        <template slot-scope="scoped">
          <span>{{ scoped.row.property == 1 ? '综合医院' : '专科医院' }}</span>
        </template>
      </el-table-column>
      <el-table-column align="center"
                       prop="phone"
                       label="联系电话"></el-table-column>
      <el-table-column align="center"
                       prop="createTime"
                       label="创建时间"
                       :formatter="formatterDate"></el-table-column>
      <el-table-column align="center"
                       prop="status"
                       label="状态"
                       width="100">
        <template slot-scope="scoped">
          <span>{{ scoped.row.status == 1 ? '启用' : '禁用' }}</span>
        </template>
      </el-table-column>

      <el-table-column align="center"
                       width="620"
                       label="操作">
        <template slot-scope="scope">
          <el-button type="primary"
                     size="mini"
                     @click="handle(3,scope.row)">编 辑
          </el-button>
          <el-button type="danger"
                     size="mini"
                     @click="handle(4,scope.row)">删 除
          </el-button>
          <el-button type="warning"
                     size="mini"
                     @click="handle(5,scope.row)">{{ scope.row.status == 0 ? '启 用' : ' 禁 用' }}
          </el-button>
          <el-button type="primary"
                     size="mini"
                     plain
                     @click="handle(6,scope.row)">业务配置
          </el-button>
          <el-button type="info"
                     size="mini"
                     @click="handle(7,scope.row)">设备管理
          </el-button>
          <el-button type="primary"
                     size="mini"
                     @click="handle(8,scope.row)">慢病签约配置
          </el-button>

        </template>
      </el-table-column>
    </el-table>
    <page @getList="_getList"
          :pageTotal="pageTotal"
          ref="page"></page>
    <adddialog v-if="showdialog"
               :dialogData='dialogData'
               :typeItems='typeItems'
               @closedialog='_getList;showdialog=false;'/>
    <el-dialog title="logo"
               center
               :visible.sync="dialogVisible"
               width="30%">
      <img :src="imgurl"
           alt=""
           style="width:100%;height:100%">
      <span slot="footer"
            class="dialog-footer">
        <el-button type="primary"
                   @click="dialogVisible = false">确 定</el-button>
      </span>
    </el-dialog>

    <el-dialog :visible.sync="showSlowConfigDialog"
               width="50%"
               :close-on-click-modal="false"
               :close-on-press-escape="false">
      <el-tabs type="border-card" v-if="showSlowConfigDialog">
        <el-tab-pane label="特享VIP服务">
          <!-- vip -->
          <view-vip :dataObj="dataObj"></view-vip>
        </el-tab-pane>
        <el-tab-pane label="慢病服务医院管理">
          <view-slow :dataObj="dataObj"></view-slow>
        </el-tab-pane>
        <el-tab-pane label="自选类配置">
          <view-optional :dataObj="dataObj"></view-optional>
        </el-tab-pane>
        <el-tab-pane label="网点设置">
          <view-websit :dataObj="dataObj"></view-websit>
        </el-tab-pane>
      </el-tabs>
      <p align="center" style="margin-top: 20px">
        <el-button @click="showSlowConfigDialog=false">返 回
        </el-button>
      </p>

    </el-dialog>
  </div>
</template>

<script>
import Page from '@/base/page/page'
import adddialog from './dialog'
import {mapGetters} from 'vuex'
import vipConfigList from '../hospitalCheck/vipConfigList'
import slowHospitalManageList from '../hospitalCheck/slowHospitalManageList'
import websitList from '../hospitalCheck/websitList'
import optionalList from "./optionalList";

export default {
  name: "healthInfo",
  data() {
    return {
      showSlowConfigDialog: false,
      dataObj: {},
      param: {},
      tableData: [],
      pageTotal: 0,
      typeItems: [],
      showdialog: false,
      dialogData: {
        show: true,
        info: {}
      },
      imgurl: '',
      dialogVisible: false,
    }
  },
  created() {
    this.post(this.api.hospitalLevel.getHospitalLevel).then(res => {
      if (res.data.code === '200') {
        this.typeItems = res.data.object;
      }
    })
    this._getList();
  },
  methods: {
    seeImg(url) {
      this.imgurl = url;
      this.dialogVisible = true;
    },
    formatterDate(row) {
      return this.commonFunction.timestampFormat(new Date(row.createTime), 'yyyy-MM-dd hh:mm:ss');
    },
    hospitallevel(row) {
      if (this.typeItems.length > 0) {
        let name = this.typeItems.filter(res => res.level == row.level) ? this.typeItems.filter(res => res.level == row.level)[0].name : ''
        return name
      }
    },
    handle(index, row) {
      switch (index) {
        case 1:
          this.page.pageIndex = 0
          this._getList()
          break
        case 2:
          this.showdialog = true
          this.dialogData = {
            show: true,
            info: null,
            title: '新增医院'
          }
          break;
        case 3:
          this.showdialog = true
          this.dialogData = {
            show: true,
            info: {id: row.id},
            title: '编辑医院'
          }
          break
        case 4:
          this.$confirm('此操作将永久删除, 是否继续?', '提示', {
            confirmButtonText: '确定',
            cancelButtonText: '取消',
            type: 'warning'
          }).then(() => {
            this.post(this.api.cooperationHospital.hospitaldel, {id: row.id}).then(res => {
              if (res.data.code === '200') {
                this.$message.success('删除成功!');
                this._getList()
              }
            })
          }).catch(() => {
            this.$message({
              type: 'info',
              message: '已取消删除'
            })
          });
          break
        case 5:
          let state
          if (row.status == 1) {
            state = 0;
          } else {
            state = 1;
          }
          this.$confirm(`您是否要${row.status == 1 ? '禁用' : '启用'}该医院 ?`, '提示', {
            confirmButtonText: '确定',
            cancelButtonText: '取消',
            type: 'warning'
          }).then(() => {
            this.post(this.api.cooperationHospital.quickConsultationHospitaluploadStatus, {
              status: state,
              id: row.id
            }).then(res => {
              if (res.data.code === '200') {
                this.$message.success(`${row.status == 1 ? '禁用' : '启用'}成功!`);
                this._getList();
              }
            })
          }).catch(() => {
            this.$message({
              type: 'info',
              message: '已取消'
            })
          });
          break
        case 6:
          this.$router.push({path: '/inspectionManagement', query: {hospitalId: row.hospitalId}});
          break
        case 7:
          this.$router.push({name: 'fetalHeart', query: {id: row.id, hospitalId: row.hospitalId}})
          break
        case 8:
          //慢病签约配置
          this.showSlowConfigDialog = true
          this.dataObj = row
          break
      }
    },
    _getList() {
      let param = {
        searchCondition: this.param.searchCondition,
        level: this.param.level,
        pageSize: this.page.pageSize,
        pageIndex: this.page.pageIndex,
      }
      this.post(this.api.cooperationHospital.getHospitalList, param).then((res) => {
        if (res.data.code === '200') {
          this.tableData = res.data.object;
          this.pageTotal = res.data.totalNum;
        }
      });
    },
    //初始化网点
    initCooperation() {
      this.post(this.api.company.initCooperation).then((res) => {
        if (res.data.code === '200') {
          this.$message.success('初始化成功')
        }
      })
    },
  },
  computed: {
    ...mapGetters([
      'page'
    ])
  },
  components: {
    Page, adddialog,
    'view-vip': vipConfigList,
    'view-slow': slowHospitalManageList,
    'view-websit': websitList,
    'view-optional': optionalList,
  }
}
</script>

<style scoped lang="scss" type="text/scss" rel="stylesheet/scss">
.information {
  margin: 10px 0px 0px 0px;
}

.el-select {
  width: 90%;
}

.editorForm {
  height: 750px;
}

.editor {
  position: fixed;
  margin-left: -70px;
  width: 70%;
  height: 700px;
  float: left;
}

.info {
  height: 750px;
  width: 30%;
  position: absolute;
  top: 78px;
}

.info .el-input {
  width: 90%;
}

.avatar-uploader {
  width: 100px;
  height: 100px;
  border: 1px dashed #606266;
  border-radius: 6px;
  cursor: pointer;
  position: relative;
  overflow: hidden;
}

.avatar-uploader:hover {
  border-color: #409eff;
}

.avatar-uploader .avatar-uploader-icon {
  font-size: 28px;
  color: #8c939d;
  width: 98px;
  height: 98px;
  line-height: 100px;
  text-align: center;
}

.avatar {
  width: 100px;
  height: 100px;
  display: block;
}

.formTitle {
  display: inline-block;
  line-height: 24px;
  font-size: 18px;
  color: #303133;
}

.return {
  float: right;
}
</style>
